package ESP.Control.E;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import com.alibaba.fastjson.JSONArray;

import ESP.Dao.BaseDao;
import ESP.Util.Encryption;

public class e03 {
	@Resource
	public BaseDao baseDao;
	/**
	 * 返回信息
	 */
	private JSONArray rows;
	private Map<String, String> message = new HashMap<String, String>();
	/**
	 * 用户信息
	 */
	private String user_role_id;
	private String user_id;
	/**
	 * 修改前、后的密码
	 */
	private String oldPassword;
	private String newPassword;
	/**
	 * 修改密码
	 */
	public String modifyPassword(){
		if (user_id == null || user_id.equals("")) {
			baseDao.setReturnInfo(message, "N", "本次登录会话失效,请重新登录!");
			return "modifyPassword";
		}
		int  i = baseDao.updatePassword(Encryption.encryptionSHA1(oldPassword),Encryption.encryptionSHA1(newPassword), user_id);
		if (i == 1) {
			baseDao.setReturnInfo(message, "Y", "密码修改成功!");
		}else {
			baseDao.setReturnInfo(message, "N", "密码修改失败,请稍后再试!");
		}
		return "modifyPassword";
	}
	/**
	 * 校验原密码
	 */
	public String checkOldPsw(){
		int  i = 0;
		if (user_id == null || user_id.equals("")) {
			baseDao.setReturnInfo(message, "N", "本次登录会话失效,请重新登录!");
			return "modifyPassword";
		}
		i = baseDao.checkPsw(user_id, Encryption.encryptionSHA1(oldPassword));
		if (i == 1) {
			baseDao.setReturnInfo(message, "Y", "校验通过!");
		}else {
			baseDao.setReturnInfo(message, "N", "原密码输入错误!");
		}
		return "modifyPassword";
	}
	/**
	 * set get
	 */
	public BaseDao getBaseDao() {
		return baseDao;
	}
	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}
	public JSONArray getRows() {
		return rows;
	}
	public void setRows(JSONArray rows) {
		this.rows = rows;
	}
	public Map<String, String> getMessage() {
		return message;
	}
	public void setMessage(Map<String, String> message) {
		this.message = message;
	}
	public String getUser_role_id() {
		return user_role_id;
	}
	public void setUser_role_id(String userRoleId) {
		user_role_id = userRoleId;
	}
	public String getUser_id() {
		return user_id;
	}
	public void setUser_id(String userId) {
		user_id = userId;
	}
	public String getNewPassword() {
		return newPassword;
	}
	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}
	public String getOldPassword() {
		return oldPassword;
	}
	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}
}
